package com.cedifie.lendapp.ui.user.impl

import com.cedifie.lendapp.MyApplication
import com.cedifie.lendapp.R
import com.cedifie.lendapp.http.ApiService
import com.cedifie.lendapp.http.ApiService.addCommonParams
import com.cedifie.lendapp.http.HttpHelper
import com.cedifie.lendapp.http.IHttpCallback
import com.cedifie.lendapp.utils.event.CedEventType
import com.cedifie.lendapp.utils.helper.SharedHelper
import org.json.JSONObject

/**
 * Cedifie
 * @Author wwdeng
 * @CreateTime: 2025/4/11 10:41
 * @Annotation：校验手机号 Model 实现
 */
class CedUserCheckPhoneNumberModelImpl {

    /**
     * 打分
     */
    fun loadCedRateUsAction(callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_STAR_COMMENT_PATH)
        }
        HttpHelper.postCedAction(httpUrl,params,callBack)
    }

    /**
     * 是否需要显示清除账号信息按钮、清除账户数据
     */
    fun clearUserDataAction(isShowButton: Boolean,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_USER_DATA_CLEAR_PATH)
        }
        if (isShowButton){
            params.put("type","GET")
        } else {
            params.put("type","DROP")
        }
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }

    /**
     * 发送WhatsApp验证码
     */
    fun sendCheckNumberWhatsAppCodeAction(mobile: String,sendType: String,callBack: IHttpCallback){
        val loginMobile = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_MOBILE)
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_WHATSAPP_SEND_CODE_PATH)
            put("mobile", loginMobile)
            put("submitMobile", mobile)
            put("sendType",sendType)
        }
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }

    /**
     * 当校验方式是”TGBOT“时，需要通过链接校验
     */
    fun loadCedCheckPhoneNumberTypeTelegramBotLinkAction(mobile: String,callBack: IHttpCallback){
        val params = JSONObject().addCommonParams().apply {
            put("path", ApiService.API_PATH.CED_API_TELEGRAM_BOT_CHECK_URL_PATH)
            put("mobile", mobile)
        }
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }

    /**
     * 校验验证码
     */
    fun onCedCheckPhoneNumberVerificationCodeAction(params: JSONObject,callBack: IHttpCallback){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.CED_API_COMMON_URL)
        HttpHelper.postCedAction(httpUrl, params, callBack)
    }
}